import { useLazyQuery } from "@apollo/client";
import {
  getTimetableRecords_simple_service,
  TimetableRecordType,
} from "../../graphql/timetableRecord";

export const useGetTimetableRecords = () => {
  const [fun, { loading }] = useLazyQuery(getTimetableRecords_simple_service, {
    fetchPolicy: "network-only",
  });

  const getTimetableRecords = async (timetableId: string) => {
    const res = await fun({
      variables: {
        page: {
          pageNum: 1,
          pageSize: 0,
        },
        timetableId,
      },
    });
    return res.data.getTimetableRecordsPc as {
      code: boolean;
      data: TimetableRecordType[];
    };
  };

  return { getTimetableRecords, loading };
};
